home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dtk_demo.zip / NUMLINES.C < prev    next >
C/C++ Source or Header  |  1991-09-12  |  2KB  |  59 lines

  1. /*  NUMLINES.C
  2.  *  last mod.: 15-SEP-91
  3.  */
  4.  
  5. #include <STDIO.H>
  6. #include <L_FILE.H>
  7.  
  8. char *usage = "Use: NUMLINES filename\n";
  9.  
  10. /*  file must be a text file  */
  11.  
  12. /*----------------------------*/
  13. void main(int argc, char **argv)
  14. {
  15. int err_flag, exclude_blank, type;
  16. Uint num_lines, k;
  17.  
  18. if ( argc < 2 )
  19.     {
  20.     printf(usage);
  21.     return;
  22.     }
  23.  
  24. type = file_type(argv[1]);
  25. if ( type == -2 )
  26.     printf("File not found.\n");
  27. else if ( type < 0 && type > -5 )
  28.     printf("Error with this file.\n");
  29. else if ( type != 2 )
  30.     printf("This is not a text file.\n");
  31. else
  32.     {
  33.     exclude_blank = TRUE;
  34.     num_lines = num_lines_in_file(argv[1],exclude_blank,&err_flag);
  35.     if ( err_flag )
  36.         {
  37.         switch ( err_flag )
  38.             {
  39.             case -2: printf("File not found.\n"); break;
  40.             case -3: printf("Error opening file.\n"); break;
  41.             case -4: printf("Error reading file.\n"); break;
  42.             case -5: printf("File is empty.\n"); break;
  43.             case -6: printf("Number of lines exceeds 65,565.\n"); break;
  44.             case -7: printf("Less than 256 bytes free in near heap.\n"); break;
  45.             default: printf("Unknown error.\n");
  46.             }
  47.         }
  48.     else
  49.         {
  50.         printf("Non-blank lines in file =%5u\n",num_lines);
  51.         k = num_lines;
  52.         exclude_blank = FALSE;
  53.         num_lines = num_lines_in_file(argv[1],exclude_blank,&err_flag);
  54.         printf("Blank lines in file =    %5u\n",num_lines-k);
  55.         printf("Total lines in file =    %5u\n",num_lines);
  56.         }
  57.     }
  58. }
  59.